package org.example;

import org.example.config.RegistryConfig;
import org.example.config.RpcConfig;
import org.example.pojo.ServiceMetaInfo;
import org.example.registry.LocalRegistry;
import org.example.registry.Registry;
import org.example.registry.RegistryFactory;
import org.example.serve.VertxHttpServer;
import org.example.serve.tcp.VertxTcpServer;
import org.example.service.UserService;
import org.example.service.UserServiceImpl;

import java.util.concurrent.ExecutionException;

public class EasyProviderExample {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //加载配置
        RpcApplication.init();
        String name = UserService.class.getName();
        //注册服务到本地注册器
        LocalRegistry.register(name,UserServiceImpl.class);
        //注册服务到注册中心
        RpcConfig rpcConfig = new RpcConfig();
        RegistryConfig registryConfig = rpcConfig.getRegistryConfig();
        Registry registry = RegistryFactory.getInstance(registryConfig.getRegistryType());
        registry.init(registryConfig);
        ServiceMetaInfo serviceMetaInfo = new ServiceMetaInfo();
        serviceMetaInfo.setServiceName(name);
        serviceMetaInfo.setServiceHost(rpcConfig.getServerHost());
        serviceMetaInfo.setServicePort(rpcConfig.getServerPort());
        registry.register(serviceMetaInfo);
        //启动服务
//        VertxHttpServer vertxHttpServer = new VertxHttpServer();
//        vertxHttpServer.start(RpcApplication.getRpcConfig().getServerPort());
        VertxTcpServer vertxTcpServer = new VertxTcpServer();
        vertxTcpServer.doStart(RpcApplication.getRpcConfig().getServerPort());
    }
}